package com.server.server_a10.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.server.server_a10.entity.Equipment;
import com.server.server_a10.entity.smog.Smog;
import com.server.server_a10.management.entity.EquipmentInf;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

@Mapper
public interface SmogMapper extends BaseMapper {
    @SelectProvider(type = ProviderSmog.class, method = "getSmogInfByRoomId")
    List<Smog> getSmogInfByRoomId(int room_id);

    @SelectProvider(type = ProviderSmog.class, method = "getSmogLimit")
    List<EquipmentInf> getSmogLimit(String name, String room_id, String home_id, int index, int limit);

    @SelectProvider(type = ProviderSmog.class, method = "getGardenLimitCount")
    int getSmogLimitCount(String name,String room_id,String home_id);

    class ProviderSmog {
        public static String getSmogInfByRoomId(int room_id) {
            return "select * from smog where room_id=#{room_id}";
        }
        public static String getSmogLimit(){
            return "select s.id as id,s.name as name,s.room_id as room_id,r.home_id as home_id,u.id as user_id,u.name as user_name\n" +
                    "from smog s\n" +
                    "    left join room r on r.id = s.room_id\n" +
                    "    left join home h on r.home_id = h.id\n" +
                    "    left join user u on h.master_id = u.id\n" +
                    "where s.id like concat('%',#{name},'%') and  s.room_id like concat('%',#{room_id},'%') and r.home_id like concat('%',#{home_id},'%')\n" +
                    "limit #{index},#{limit}";
        }
        public static String getGardenLimitCount(){
            return "\n" +
                    "select count(*)\n" +
                    "from smog s\n" +
                    "         left join room r on r.id = s.room_id\n" +
                    "         left join home h on r.home_id = h.id\n" +
                    "         left join user u on h.master_id = u.id\n" +
                    "where s.id like concat('%',#{name},'%') and  s.room_id like concat('%',#{room_id},'%') and r.home_id like concat('%',#{home_id},'%');\n";
        }
    }
}
